//
//  PaperMaterialScrollView.m
//  智云题库
//
//  Created by 毕武侠 on 2017/3/22.
//  Copyright © 2017年 bwx. All rights reserved.
//

#import "PaperMaterialScrollView.h"

@interface PaperMaterialScrollView ()

@property (nonatomic, strong) YYLabel *textLabel;    // 材料

@end

@implementation PaperMaterialScrollView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setupConfigure];
    }
    return self;
}

- (instancetype)init {
    self = [super init];
    if (self) {
        [self setupConfigure];
    }
    return self;
}

- (void)setupConfigure {
    //可以达到同一界面上多个控件接受事件时的排他性,从而避免一些问题。也就是说避免在一个界面上同时点击多个button。
    self.exclusiveTouch = YES;
    // 加载题目View
    self.textLabel.frame = CGRectMake(12, 0, self.width - 24.0f, 12);
    [self addSubview:self.textLabel];
}

- (void)setTextLayout:(YYTextLayout *)textLayout {
    _textLayout = textLayout;
    [self refreshView];
}

- (void)refreshView {
    [self setContentOffset:CGPointZero animated:NO];
    
    // text
    self.textLabel.height = self.textLayout.textBoundingSize.height;
    self.textLabel.textLayout = self.textLayout;
    self.contentSize = CGSizeMake(SCREEN_WIDTH, self.textLabel.height + 24.0f);
}

#pragma mark - getter

- (YYLabel *)textLabel {
    if (_textLabel == nil) {
        _textLabel = [YYLabel new];
        _textLabel.textVerticalAlignment = YYTextVerticalAlignmentTop;
        _textLabel.displaysAsynchronously = YES;
        _textLabel.ignoreCommonProperties = YES;
        _textLabel.fadeOnAsynchronouslyDisplay = NO;
        _textLabel.fadeOnHighlight = NO;
    }
    return _textLabel;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
